# 14、推导式2
# 1）过滤出长度大于3的人名
name = ['tom', 'lily', 'jacks', 'Pe', 'Steven']
li1 = [i for i in name if len(i) > 3]
print(li1)

# 2）得到嵌套列表中每个列表的最后一个元素
list1 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
list2 = [e[-1] for e in list1]
print(list2)

# 3）员工工资>5000的人加200，否则加500
dict1 = {'name': '张三', 'salary': 6000}
dict2 = {'name': '李四', 'salary': 8000}
dict3 = {'name': '王五', 'salary': 4000}
dict4 = {'name': '吴二', 'salary': 3000}
list2 = [dict1, dict2, dict3, dict4]
list3 = {x['salary'] + 200 if x['salary'] > 5000 else x['salary'] + 500 for x in list2}
print(list3)
li6 = [(x['name'], x['salary'] + 200 if x['salary'] > 5000 else x['salary'] + 500) for x in list2]
print(li6)

# 4）找到分数60分以下的人姓名
scores = {
    "Rick Sanchez": 70,
    "Morty Smith": 35,
    "Summer Smith": 82,
    "Jerry Smith": 23,
    "Beth Smith": 98
}
dic2 = {key for key, value in scores.items() if value < 60}
print(dic2)
